6 public static void main(String
[] args
) throws IOException
{
7 BufferedReader reader
= new BufferedReader(new InputStreamReader(System
.in
));
8 String line
= reader
.readLine();
9 StringTokenizer tokenizer
= new StringTokenizer(line
);
10 int N
= Integer
.valueOf(tokenizer
.nextToken());
13 a
= reader
.readLine();
14 b
= reader
.readLine();
16 int A
= a
.length(), B
= b
.length();
18 System
.out
.println("0");
20 BigInteger dp
[][] = new BigInteger
[2][A
];
22 dp[i][j] = cantidad de maneras diferentes
23 en que puedo distribuir las primeras i
24 letras de la subsecuencia (b) terminando
25 en la letra j de la secuencia original (a)
28 if (a
.charAt(0) == b
.charAt(0)){
29 dp
[0][0] = BigInteger
.ONE
;
31 dp
[0][0] = BigInteger
.ZERO
;
33 for (int j
=1; j
<A
; ++j
){
34 dp
[0][j
] = dp
[0][j
-1];
35 if (a
.charAt(j
) == b
.charAt(0)){
36 dp
[0][j
] = dp
[0][j
].add(BigInteger
.ONE
);
40 for (int i
=1; i
<B
; ++i
){
41 dp
[i
%2][0] = BigInteger
.ZERO
;
42 for (int j
=1; j
<A
; ++j
){
43 dp
[i
%2][j
] = dp
[i
%2][j
-1];
44 if (a
.charAt(j
) == b
.charAt(i
)){
45 dp
[i
%2][j
] = dp
[i
%2][j
].add(dp
[(i
+1)%2][j
-1]);
49 System
.out
.println(dp
[(B
-1)%2][A
-1].toString());